import React, { Component } from 'react'
import pubsub from 'pubsub-js'
export default class A extends Component {
  constructor(){
    super()
    this.state={
      msg:''
    }
  }
  getMsg=(arg1,arg2)=>{
    this.setState({
      msg:arg2
    })
  }
  componentDidMount(){
    pubsub.subscribe('send',this.getMsg)
  }

  componentWillUnmount(){
    pubsub.unsubscribe('send')
  }

  render() {
    const {msg}=this.state
    return (
      <div style={{width:'200px',height:'200px',backgroundColor:'red'}}>{msg}</div>
    )
  }
}
